class BoardCommentsController < ApplicationController
  before_filter :auth 

  def index
    list
    render :action => 'list'
  end

  # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
  verify :method => :post, :only => [ :destroy, :create, :update ],
         :redirect_to => { :action => :list }

  def list
    @board_comment_pages, @board_comments = 
		paginate :board_comments, 
			:conditions => 
				['board_post_id = ? AND (fl_enable = 1 OR user_id = ? )',params[:board_post_id],session[:user_id]],
#			:order => 'register_date DESC',
			:per_page => 10
  end

  def show
    @board_comment = BoardComment.find(params[:id])
  end

  def new
    @board_comment = BoardComment.new
    @board_comment.fl_enable = 1
  end

  def create
    @board_comment = BoardComment.new(params[:board_comment])
    @board_comment.user_id = session[:user_id]
    if @board_comment.save
      flash[:notice] = 'BoardComment was successfully created.'
#      redirect_to :action => 'list'
    else
      render :action => 'new'
    end
  end

  def edit
    @board_comment = BoardComment.find(params[:id])
  end

  def update
    	@board_comment = BoardComment.find(params[:id])

    	if(@board_comment.user_id != session[:user_id])
	   flash[:notice] = "not added user"
#  	   redirect_to :action => "show", :id=>@board_comment
    	else
	    if @board_comment.update_attributes(params[:board_comment])
	      flash[:notice] = 'BoardComment was successfully updated.'
#	      redirect_to :action => 'show', :id => @board_comment
	    else
	      render :action => 'edit'
	    end
	end
  end

  def destroy
    BoardComment.find(params[:id]).destroy
    redirect_to :action => 'list'
  end
end
